ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Tracking logged-in members watching video

December 18, 2009 7:56am

Subscribe [1]
  • #1 / Dec 18, 2009 7:56am

    Frank Harrison

    154 posts

    Hi All

    I’m building a video site that includes a membership system. You can only view videos if logged in. My client wants a way to track:

    1) Which videos a particular member has watched

    2) Which members have viewed a particular video and when

    Ideally they should be able to see all of this in a nice graphical way, rather than a crude list of usernames etc. Being able to view, for example, the activity from the last 24 hours/week/month etc would be good.

    Any ideas how to go about this? Ideally we’d be tracking actual clicks on play buttons. Is there a way that Google Analytics could be used to record specific users watching specific videos?


    Thanks loads for any help!

  • #2 / Dec 18, 2009 9:43am

    ender

    1644 posts

    it depends on which player you’re using for your videos, but yes most of the good flash players have a javascript API.  After you’ve got access to the video player’s events then you can record custom analytics events to track who is doing what.

    Here’s an example of recording youtube video start and stop with google analytics:

    <div id="ytapiplayer">
        You need Flash player 8+ and JavaScript enabled to view this video.
    </div>
    [removed]
        var params = { allowScriptAccess: "always" };
        var atts = { id: "myytplayer" };
        swfobject.embedSWF("http://www.youtube.com/v/<video id goes here>?enablejsapi=1&playerapiid=ytplayer&hl=en&fs=1&rel=0&showinfo=0", "ytapiplayer", "520", "316", "8", null, null, params, atts);
    
        // initialize google analytics and save pageTracker as a global variable to reference in the functions below
    
        function onYouTubePlayerReady(playerId) {
            ytPlayer = document.getElementById("myytplayer");
            ytPlayer.addEventListener("onStateChange", "onPlayerStateChange");
        }
    
        function onPlayerStateChange(newState) {
            if(pageTracker === false && window.console) {
                console.log〈"YT Event before pageTracker ready"〉;
            }
            var state = translateYTPState(newState);
        
            if(!ytPlayerState && state == "playing" && pageTracker !== false) {
                pageTracker._trackEvent('Video', 'Started', [removed].href);
                ytPlayerState = "started";
            } else if(ytPlayerState == "started" && state == "ended" && pageTracker !== false) {
                pageTracker._trackEvent('Video', 'Finished', [removed].href);
                ytPlayerState = "finished";
            }
        }
    
        function translateYTPState(state) {
            switch (state) {
                case -1: return "unstarted";
                case 0 : return "ended";      // at the end of the video
                case 1 : return "playing";    // whenever the video starts playing after buffering or after paused
                case 2 : return "paused";     // whenever you pause/stop the video
                case 3 : return "buffering";  // between video cued and playing, also if you skip through the video's timeline
                case 5 : return "video cued"; // on page load… basically the preview
            }
            return;
        }
    [removed]
  • #3 / Dec 20, 2009 11:56am

    Frank Harrison

    154 posts

    Thanks ender. I’m going to be using the JW flash player. So if I understand right, can I have google analytics keep track of specifically who watches each film (by the member’s user name, for example), then display the activity of a particular user, or display who’s been watching a particular video? It’d be great to to be able to check both of these stats for different periods of time (last 24 hours, last week etc). It would also be useful to be able to list all recent activity (any user viewing any video, listed by username and video title).

    If this is possible, are there any tutorials that would show how to do this kind of thing? (I’m pretty basic with google analytics…)

    Thanks loads for any help!

  • #4 / Dec 21, 2009 9:58am

    ender

    1644 posts

    google events have three values: category, action, and label.  of course the day on which the event occurs is also recorded for use in the timeline.

    You would probably use category: “video playback”, action: {member_id}, label: {entry_id} (some sort of identifier for the video). 

    You can then view events over a particular time period by action or by label.  Viewing by action would show you all of the videos that a particular member watched.  Viewing by label would show you how many times a particular video got watched.

  • #5 / Dec 21, 2009 10:55am

    Frank Harrison

    154 posts

    Thanks ender - I’ll have a play with that. Would there be any way to see who has watched a particular video? Or to list all recent activity? It’d great if I could display a list of all video watching activity, showing the user name and video name.

  • #6 / Dec 21, 2009 12:31pm

    ender

    1644 posts

    all of that is possible via google analytics if you select your action and label values wisely.

  • #7 / Dec 21, 2009 12:33pm

    Frank Harrison

    154 posts

    Ok - will spend some time trying this out. Thanks loads for all your help!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases